package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Author mr.zhao
 * @Date 2025/7/1 14:36
 */
@RestController("addressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 地址薄相关接口")
public class AddressBookController {
	@Autowired
	private IAddressBookService addressBookService;

	@PostMapping
	@ApiOperation("新增地址薄")
	public void addAddressBook(@RequestBody AddressBookUpsertReqDTO dto){
		addressBookService.add(dto);
	}

	@GetMapping("/page")
	@ApiOperation("地址薄分页查询")
	public PageResult<AddressBookResDTO> page(AddressBookPageQueryReqDTO dto){
		PageResult<AddressBookResDTO> result = addressBookService.pageList(dto);
		return result;
	}

	@GetMapping("/{id}")
	@ApiOperation("地址薄根据id查询")
	public AddressBook getById(@PathVariable Long id){
		AddressBook result = addressBookService.getById(id);
		return result;
	}

	@PutMapping("/{id}")
	@ApiOperation("地址薄更新")
	public void update(@PathVariable Long id,@RequestBody AddressBookUpsertReqDTO dto){
		addressBookService.updateAB(id,dto);
	}

	@DeleteMapping("/batch")
	@ApiOperation("地址薄删除")
	public void batchDelete(@RequestBody String ids){
		addressBookService.batchDelete(ids);
	}

	@PutMapping("/default")
	@ApiOperation("地址簿默认操作")
	public void updateDefault(@RequestParam("id") Long id,@RequestParam Integer flag){
		addressBookService.updateDefault(id,flag);
	}

	@GetMapping("/defaultAddress")
	@ApiOperation("获取地址簿默认地址")
	public AddressBook getDefaultAddress(){
		AddressBook addressBook = addressBookService.getDefaultAddress();
		return addressBook;
	}
}
